<?php

namespace app\admin\model\fastflow\bill;

use app\admin\model\AuthGroup;
use app\admin\model\AuthGroupAccess;


class FastflowDemoLeave extends Common
{


    // 表名
    protected $name = 'fastflow_demo_leave';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $appendAttr = [
        'status_text',
        'type_text',
        'group',
        'sex_text',
    ];


    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3')];
    }

    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3')];
    }

    public function getSexList()
    {
        return ['0' => __('Sex 0'), '1' => __('Sex 1')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getSexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
        $list = $this->getSexList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getGroupAttr($value, $data)
    {
        $initiator_id = $data['initiator_id'];
        $group_access = (new AuthGroupAccess())->where(['uid' => $initiator_id])->select();
        $group_ids = [];
        foreach ($group_access as $access) {
            $group_ids[] = $access['group_id'];
        }
        $group_lst = AuthGroup::all($group_ids);
        $group_name_lst = [];
        foreach ($group_lst as $group) {
            $group_name_lst[] = $group['name'];
        }
        return implode(',',$group_name_lst);
    }

}
